<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class ShopBackEndController extends BackEndController {
    protected $shop;

    public function __construct() {
        parent::__construct();
        $this->load->helper('shop');
        $this->load->model('repo/shop_model', 'shop_model');
        $this->shop = $this->shop_model->getShopByUserId($this->user_id, array('a.id','a.slug, c.image_folder'));
        if ($this->shop==null || count($this->shop)==0) {
            if ($this->input->is_ajax_request()) {
                $a = array('code' => E_SESSION_TIMEOUT, 'login_href' => page_url('dang-nhap'));
                echo json_encode($a);
                die();
            } else {
                redirect(page_url('dang-nhap'));
            }
        }
    }

    public function checkRole() {
        if ($this->role!=ROLE_SHOP_OWNER && $this->role!=ROLE_ADVERTISER){
        	header('location:'.page_url('dang-nhap'));
        }
    }

    public function renderView($viewName, $data = null) {
        $data['shop']        = $this->shop;
        $data['role_folder'] = 'shop';
        $this->loadView('backend/layout/layout', $viewName, $data);
    }
}
?>